package com.anlu.base;

import lombok.extern.slf4j.Slf4j;

/**
 * Hello world!
 *
 */
@Slf4j
public class App 
{
    public static void main( String[] args ) throws RemoteServiceException {
        System.out.println( "Hello World!" );

        var serverStartTime = System.nanoTime();

        var delayedService = new DelayedRemoteService(serverStartTime, 5);
        var delayedServiceCircuitBreaker = new DefaultCircuitBreaker(delayedService, 3000, 2,
                2000 * 1000 * 1000);

        var quickService = new QuickRemoteService();
        var quickServiceCircuitBreaker = new DefaultCircuitBreaker(quickService, 3000, 2,
                2000 * 1000 * 1000);
        //Create an object of monitoring service which makes both local and remote calls
        var monitoringService = new MonitoringService(delayedServiceCircuitBreaker,
                quickServiceCircuitBreaker);

        //Fetch response from local resource
        log.info(monitoringService.localResouceResponse());

        //Fetch response from delayed service 2 times, to meet the failure threshold
        log.info(monitoringService.delayedServiceResponse());
        log.info(monitoringService.delayedServiceResponse());
    }
}
